<?php require_once('../Connections/cnn.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "Admin,User";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../error.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE categorias SET Estado=%s WHERE IdCategoria=%s",
                       GetSQLValueString($_POST['Estado'], "text"),
                       GetSQLValueString($_POST['IdCategoria'], "int"));

  mysql_select_db($database_cnn, $cnn);
  $Result1 = mysql_query($updateSQL, $cnn) or die(mysql_error());

  $updateGoTo = "lista_cat.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_cnn, $cnn);
$query_categorias = "SELECT * FROM categorias";
$categorias = mysql_query($query_categorias, $cnn) or die(mysql_error());
$row_categorias = mysql_fetch_assoc($categorias);
$totalRows_categorias = mysql_num_rows($categorias);
?>
<!doctype html>
<html><!-- InstanceBegin template="/Templates/plantilla.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ventas</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../css/estilo.css" rel="stylesheet" type="text/css">

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>

<![endif]-->

<!-- InstanceBeginEditable name="1" -->
<link href="../css/menu2.css" rel="stylesheet" type="text/css">
<!-- Skitter JS -->


<![endif]-->


<!-- InstanceEndEditable -->
</head>


<body> 

 <script type="text/javascript">
            $(document).ready(function() {
                $('.menu').tagdrop({tagPaddingTop: '60px',bgColor: '#B1CCED',bgMoverColor: '#7FB0F0',textColor: '#e0e0e0'});
            });
        </script>
<div class="container">
  <header>
    <img src="../images/banner.png" width="960" height="194" />
 
 
  </header>
   <ul class="menu2">
 
    <li><a href="index2.php">Inicio</a></li>
    <li><a href="Agregar_Cat.php">Agregar Categorias</a></li>
    <li><a href="lista_prod.php">Regresar</a></li>


    
</ul>

  <!-- InstanceBeginEditable name="2" -->


  <table width="400" height="206"  border="2" align="center" id="sidebar9">
  <tr bgcolor="#00CCFF">
    <td><p>Categoria<p></td>
    <td><p>Acción<p></td>
  </tr>
  <?php do { ?>
    <tr bgcolor="#6699CC">
      <td><?php echo $row_categorias['strNombre']; ?></td>
      <td><form method="post" name="form1" action="<?php echo $editFormAction; ?>">
        <table align="center" id="estado">
          <tr valign="baseline">
            <td nowrap align="right">Estado:</td>
            <td><select name="Estado">
              <option value="Habilitado" <?php if (!(strcmp("Habilitado", htmlentities($row_categorias['Estado'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>Habilitado</option>
              <option value="Deshabilitado" <?php if (!(strcmp("Deshabilitado", htmlentities($row_categorias['Estado'], ENT_COMPAT, 'utf-8')))) {echo "SELECTED";} ?>>Deshabilitado</option>
            </select></td>
          </tr>
          <tr valign="baseline">
            <td nowrap align="right">&nbsp;</td>
            <td><input type="submit" value="Actualizar Estado"></td>
          </tr>
        </table>
        <input type="hidden" name="MM_update" value="form1">
        <input type="hidden" name="IdCategoria" value="<?php echo $row_categorias['IdCategoria']; ?>">
      </form>
        <p>&nbsp;</p>
        <td bgcolor="#66FFFF"><p><a href="Edit-cat.php?IdCategoria=<?php echo $row_categorias['IdCategoria']; ?>"><h3>Editar</h3></a></p></td></td>
    </tr>
    <?php } while ($row_categorias = mysql_fetch_assoc($categorias)); ?>
  </table>



  <!-- InstanceEndEditable -->
  <!-- script del menu -->

  <footer>
    <h3>Super Gangas</h3>
  </footer>
  <!-- end .container --></div>
</body>
<!-- InstanceEnd -->


</html>
<?php
mysql_free_result($categorias);
?>
